package com.ms.education.course.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ms.education.R;
import com.ms.education.course.entity.Course;
import com.ms.education.course.entity.vo.PageCourseVo;
import com.ms.education.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-01-17
 */
@RestController
@RequestMapping("/course/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("pageCourse/{current}/{limit}")
    public R pageCourse(@RequestBody PageCourseVo pageCourseVo,
                        @PathVariable("current") long current,
                        @PathVariable("limit") long limit) {
        Map<String, Object> res = courseService.pageCourse(pageCourseVo, current, limit);
        return R.ok().data(res);
    }

    @GetMapping("getCourseById/{id}")
    public R getCourseById(@PathVariable("id") Integer id,
                           Boolean isContainChapter,
                           Boolean isContainComment) {
        return courseService.getCourseById(id, isContainChapter, isContainComment);
    }

    @PostMapping("deleteCourseByIds")
    public R deleteCourseByIds(@RequestBody Integer[] ids) {
        return courseService.deleteCourseByIds(ids);
    }

    @PostMapping("updateCourse")
    public R updateCourse(@RequestBody Course course) {
        courseService.updateById(course);
        return R.ok();
    }

    @PostMapping("saveOrUpdateCourse")
    public R saveOrUpdateCourse(@RequestBody Course course) {
        courseService.saveOrUpdateCourse(course);
        return R.ok().data("courseId", course.getId());

    }

    //查询某天新增的课程数
    @GetMapping("countCourseAdd/{day}")
    public R countCourseAdd(@PathVariable("day") String day) {
        Integer count = courseService.countCourseAdd(day);
        return R.ok().data("count", count);
    }


}
